package com.bcqn.service.impl;

import com.bcqn.dao.ConfigMapper;
import com.bcqn.model.Config;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ConfigService {

    @Resource
    private ConfigMapper configMapper;

    public int add(Config record) {
        return configMapper.insertSelective(record);
    }

    public int update(Config config) {
        return configMapper.updateByPrimaryKeySelective(config);
    }

    public int del(Long id) {
        return configMapper.deleteByPrimaryKey(id);
    }

    public PageInfo<Config> getAll(int type, int pageSize, int currentPage) {
        PageHelper.startPage(currentPage, pageSize);
        List<Config> list = configMapper.getAll(type);
        return new PageInfo<>(list);
    }

    public List<Config> queryOnline(int type) {
        return configMapper.queryOnline(type, new Date());
    }

    public Config getById(Long id) {
        return configMapper.selectByPrimaryKey(id);
    }
}
